<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body style="height: 3000px;">
  
  <div id="app">
    <button @click="isShow=!isShow">{{ isShow?'隐藏':'显示' }}</button>
    <keep-alive>
      <home v-if="isShow"></home>
    </keep-alive>
    
  </div>
  <script src="./vue.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          <input v-model="msg"/>
        </div>
      `,
      data () {
        return {
          msg: '',
          
        }
      },
      methods: {
        fetchData(){
          console.log('我是一个请求函数，请求猜你喜欢的数据')
        }
      },
      beforeCreate() {
        console.log("实例初始化完成之前")
      },
      created () {
        console.log("实例初始化完成-- created");
        this.fetchData();
      },
      beforeMount(){
        console.log('dom编译之前')
      },
      mounted(){
        console.log('dom已经渲染')
      },
      beforeUpdate() {
        console.log('数据改变dom更新之前')
      },
      updated() {
        console.log('数据改变，dom更新完毕')
      },
      beforeDestroy() {
        console.log('实例销毁之前')
        
      },
      destroyed() {
        console.log('实例已经销毁')
      },
      activated () {
        console.log('组件被激活时调用');
        this.fetchData();
      },
      deactivated () {
        console.log('组件被停用时触发')
        // 做之前beforeDestory操作 注销window上全局事件、清除定时器
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app',
      data:{
        isShow: true
      }
    })
  </script>
</body>
</html>